//
//  FXTMineHeaderView.m
//  OfferJob
//
//  Created by 郑州动力无限科技 on 2017/7/5.
//  Copyright © 2017年 郑州动力无限科技. All rights reserved.
//

#import "FXTMineHeaderView.h"
@interface FXTMineHeaderView ()
@property (nonatomic,strong)UIButton * headerBtn;
@property (nonatomic,strong)UIButton * accountBtn;
@property (nonatomic,strong)UIButton * jifenBtn;
@property (nonatomic,strong)UIButton * bailBtn;
@property (nonatomic,strong)UILabel * nameLabel;
@property (nonatomic,strong)UILabel * invitationLabel;
@end
@implementation FXTMineHeaderView
-(UIButton * )headerBtn{
    if (!_headerBtn) {
        _headerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _headerBtn.frame = CGRectMake(SCREEN_WIDTH/2-80/2, 50, 80, 80);
        _headerBtn.layer.masksToBounds = YES;
        _headerBtn.layer.cornerRadius = 40;
        [_headerBtn sd_setImageWithURL:[NSURL URLWithString:self.userModel.header_pic]  forState:UIControlStateNormal placeholderImage:ImageNamed(@"icon_logo")];
        [_headerBtn setAdjustsImageWhenHighlighted:NO];
        [_headerBtn addTarget:self action:@selector(hearderOption) forControlEvents:UIControlEventTouchUpInside];
    }return _headerBtn;
}
-(UIButton * )accountBtn{
    if (!_accountBtn) {
        _accountBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _accountBtn.frame = CGRectMake(0,CGRectGetMaxY(self.invitationLabel.frame)+20,(SCREEN_WIDTH-2)/3, 75);
        _accountBtn.tag = 0 ;
        _accountBtn.backgroundColor = [UIColor clearColor] ;
        [_accountBtn setAdjustsImageWhenHighlighted:NO];
        [_accountBtn setTitle:@"      0 \n账户余额" forState:UIControlStateNormal];
        [_accountBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        [_accountBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
        [_accountBtn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
        _accountBtn.titleLabel.numberOfLines = 0;
        _accountBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _accountBtn.layer.borderWidth = 1.0f;
    }return _accountBtn;
}
-(UIButton * )jifenBtn{
    if (!_jifenBtn) {
        _jifenBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _jifenBtn.frame = CGRectMake(CGRectGetMaxX(self.accountBtn.frame)+1,CGRectGetMaxY(self.invitationLabel.frame)+20,(SCREEN_WIDTH-2)/3, 75);
        _jifenBtn.tag = 1 ;
        _jifenBtn.backgroundColor = [UIColor clearColor] ;
        [_jifenBtn setTitle:@"      0 \n信用积分" forState:UIControlStateNormal];
        [_jifenBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
        [_jifenBtn setAdjustsImageWhenHighlighted:NO];
        [_jifenBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        _jifenBtn.titleLabel.numberOfLines = 0;
        _jifenBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _jifenBtn.layer.borderWidth = 1.0f;
    }return _jifenBtn;
}
-(UIButton * )bailBtn{
    if (!_bailBtn) {
        _bailBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _bailBtn.frame = CGRectMake(CGRectGetMaxX(self.jifenBtn.frame)+1,CGRectGetMaxY(self.invitationLabel.frame)+20,(SCREEN_WIDTH-2)/3, 75);
        _bailBtn.tag = 2 ;
        _bailBtn.backgroundColor = [UIColor clearColor];
         [_bailBtn setTitle:@"保证金" forState:UIControlStateNormal];
        [_bailBtn  setImage:[UIImage  imageNamed:@"icon_weijiaoo@2x"] forState:UIControlStateNormal];
       [ _bailBtn TiaoZhengButtonWithOffsit:5 TextImageSite:UIButtonTextBottom];
        [_bailBtn setAdjustsImageWhenHighlighted:NO];
        [_bailBtn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
        [_bailBtn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
        _bailBtn.layer.borderColor = [UIColor whiteColor].CGColor;
        _bailBtn.layer.borderWidth = 1.0f;
    }return _bailBtn;
    
    
    
    
    
    
}

-(UILabel *)nameLabel{
    if (!_nameLabel) {
       _nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.headerBtn.frame)+10, SCREEN_WIDTH, 20)];
        _nameLabel.font = [UIFont systemFontOfSize:16];
        _nameLabel.textColor = [UIColor whiteColor];
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.text = @"登录/注册";
    }return _nameLabel;
}

-(UILabel *)invitationLabel{
    if (!_invitationLabel) {
        _invitationLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(self.nameLabel.frame)+10, SCREEN_WIDTH, 20)];
        _invitationLabel.font = [UIFont systemFontOfSize:16];
        _invitationLabel.textColor = [UIColor whiteColor];
        _invitationLabel.textAlignment = NSTextAlignmentCenter;
        _invitationLabel.text = @"";
    }return _invitationLabel;
}
- (void)drawRect:(CGRect)rect {
    // Drawing code

    [self addSubview:self.headerBtn];
    
    [self addSubview:self.nameLabel];
    
    [self addSubview:self.invitationLabel];
    
    [self addSubview:self.accountBtn];
    
    [self addSubview:self.jifenBtn];
    
    [self addSubview:self.bailBtn];
    
}
-(void)hearderOption{
    if ([self.delegate respondsToSelector:@selector(alertPersonView)]) {
        [_delegate alertPersonView];
    }
}
- (void)btnAction:(id)sender{
    UIButton * btn = (UIButton *)sender;
    if ([self.delegate respondsToSelector:@selector(touchThreeButton:)]) {
        [_delegate touchThreeButton:btn.tag];
    }
}
-(void)setUserModel:(FXTUserModel *)userModel{
    [self.headerBtn sd_setImageWithURL:[NSURL URLWithString:userModel.header_pic]  forState:UIControlStateNormal placeholderImage:ImageNamed(@"icon_logo")];
    self.nameLabel.text = userModel.telephone;
    self.invitationLabel.text = [NSString stringWithFormat:@"我的邀请码: %@",userModel.exten_code];
    [self.accountBtn setTitle:[NSString stringWithFormat:@"%@ \n账户余额",userModel.balance] forState:UIControlStateNormal];
    [self.jifenBtn setTitle:[NSString stringWithFormat:@"%@ \n信用积分",userModel.credit_score] forState:UIControlStateNormal];
}
@end
